package es.ucm.is.www.GUI.client.panels;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.WindowResizeListener;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.CaptionPanel;
import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import es.ucm.is.www.GUI.client.Root;

/**
 * <p>Title: GenericPanel.java </p>
 *
 * <p>Description: Panel generico</p>
 *
 * <p>Copyright: </p>
 *
 * @author 
 * @version 1.0
 * @see
 */
public class GenericPanel extends PopupPanel{
	
	public static GenericPanel POPUP_ACTUAL;
	
	private CaptionPanel panel; 
	private VerticalPanel vertical;
	private AbsolutePanel fondo;
	private WindowResizeListener listener;
	/**
	 * Constructora de la clase
	 */
	public GenericPanel(){
		
	}
	/**
	 * Constructora de la clase
	 * @param autoHide: indica si el panel debe ocultarse o no
	 * @param caption: texto del panel
	 */
	public GenericPanel(boolean autoHide,String caption){
		super(autoHide);
		//setPopupPosition(RootPanel.get().getOffsetWidth()/2,RootPanel.get().getOffsetHeight()/2);
		setAnimationEnabled(true);
		//this.setStyleName("fondoGenericPanel");
		panel = new CaptionPanel();
		panel.setCaptionHTML("<FONT FACE=\"Verdana\" SIZE=5 COLOR=#333>" + caption + "</FONT>");
		panel.setStyleName("genericPanel");
		vertical = new VerticalPanel();
		vertical.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
		//vertical.add(element);
		//vertical.add(cerrar);
		vertical.setStyleName("panelVerticalInGenericPanel");
		panel.setContentWidget(vertical);
		this.getElement().setId("GenericPanel");
		fondo = new AbsolutePanel();
		fondo.setPixelSize(RootPanel.get().getOffsetWidth(), RootPanel.get().getOffsetHeight());
		fondo.setStyleName("glass");
		Root.fondo = fondo;
		final GenericPanel aux = this;
		listener = new WindowResizeListener(){

			public void onWindowResized(int width, int height) {
				aux.center();
				fondo.setPixelSize(Window.getClientWidth(), Window.getClientHeight());
			}
			
		};
		Window.addWindowResizeListener(listener);
		setWidget(panel);
	}
	/**
	 * Metodo para insertar widgets en el panel
	 * @param w: el widget a insertar
	 */
	public void insertarWidget(Widget w){
	//	vertical.clear();
		vertical.add(w);
		//vertical.add(cerrar);
	}
	/**
	 * Metodo para mostrar el panel
	 */
	public void mostrar(){
		RootPanel.get().add(fondo, 0, 0);
		center();
	}
	/**
	 * Metodo para ocultar el panel
	 */
	public void ocultar(){
		Window.removeWindowResizeListener(listener);
		RootPanel.get().remove(fondo);
		hide();
	}
	
}
